<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f"%>
<%@ taglib uri="/mytag" prefix="yjd"%>
<div class="wrap">
    <div class="nav">
        <div class="return">
            <a href='<yjd:url url="/commodit/list"/>'>返回上一级</a>
        </div>
    </div>
    <form method="post" enctype="multipart/form-data" class="J_ajaxForm" autocomplete="off" action='<yjd:url url="/commodit/edit/submit"/>'>
        <input type="hidden" name="id" value="${commodit.id}">
        <input type="hidden" name="org_id" value="${commodit.org_id}">
        <div class="table_full">
            <table width="100%">
                <tr>
                    <th width="100">商品名称</th>
                    <td>
                        <input name="project_name" type="text" class="input length_5" value="${commodit.project_name}">
                    </td>
                    <td><div class="fun_tips"></div></td>
                </tr>
                <tr>
                    <th width>商品图片</th>
                    <td>
                        <input type="hidden" name="project_pic" value="${commodit.project_pic}">
                        <img id="project_pic" src="${commodit.strMap.picUrl}" />
                        <input style="width: 70px" type="file" id="picData" name="picData">
                    </td>
                    <td><div class="fun_tips"></div></td>
                </tr>
                <tr>
                    <th width>类目</th>
                    <td>
                        <select name="category_id" class="mr10"}>
                            <c:forEach items="${categorys }" var="item">
                                <option ${item.id==commodit.category_id?"selected='selected'":"" } value="${item.id }">${item.name }</option>
                            </c:forEach>
                        </select>
                    </td>
                    <td><div class="fun_tips"></div></td>
                </tr>
                <tr>
                    <th>商品详情</th>
                    <td><textarea class="length_5" name="intro">${commodit.intro}</textarea></td>
                    <td><div class="fun_tips"></div></td>
                </tr>
                <tr>
                    <th width>售价</th>
                    <td><input id="project_price" name="project_price" class="input length_5" value="${commodit.project_price}" onkeyup="value=value.replace(/[^\d]/g,'')"
                               onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">&nbsp;元</td>
                    <td><div class="fun_tips"></div></td>
                </tr>
                <tr>
                    <th width>服务次数</th>
                    <td><input name="times" class="input length_5" value="${commodit.times}" onkeyup="value=value.replace(/[^\d]/g,'')"
                               onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" >&nbsp;次</td>
                    <td><div class="fun_tips"></div></td>
                </tr>
                <tr>
                    <th width>服务时长</th>
                    <td><input name="time_limit" class="input length_5" value="${commodit.time_limit}" onkeyup="value=value.replace(/[^\d]/g,'')"
                               onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" >&nbsp;个月</td>
                </tr>
            </table>
        </div>
        <div class="btn_wrap">
            <div class="btn_wrap_pd">
                <button class="btn btn_submit mr10 J_ajax_submit_btn" type="submit">提交</button>
            </div>
        </div>
    </form>
</div>
<script>
    //更改图片
    $('#picData').on('change',function(){
        var filePath = $(this).val(),
            fileFormat = filePath.substring(filePath.lastIndexOf(".")).toLowerCase(),
            src = window.URL.createObjectURL(this.files[0]);

        if( !fileFormat.match(/.JPEG|.jpeg|.JPG|.jpg|.GIF|.gif|.BMP|.bmp|.PNG|.png/) ) {
            alert('图片格式不正确!');
            return;
        }
        $('#project_pic').attr('src',src);
    });
</script>